<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\SystemSetting;

class SystemSettingSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $settings = [
            // 基本信息设置
            [
                'key' => 'site_name',
                'value' => 'Laravel Open Admin',
                'type' => 'text',
                'group' => 'general',
                'label' => '网站名称',
                'description' => '系统显示的网站名称',
                'is_public' => true,
                'is_required' => true,
                'sort_order' => 1
            ],
            [
                'key' => 'site_description',
                'value' => '基于Laravel构建的开源管理系统',
                'type' => 'textarea',
                'group' => 'general',
                'label' => '网站描述',
                'description' => '网站的简短描述信息',
                'is_public' => true,
                'is_required' => false,
                'sort_order' => 2
            ],
            [
                'key' => 'site_version',
                'value' => '1.0.0',
                'type' => 'text',
                'group' => 'general',
                'label' => '系统版本',
                'description' => '当前系统版本号',
                'is_public' => true,
                'is_required' => false,
                'sort_order' => 3
            ],
            [
                'key' => 'site_logo',
                'value' => '/images/logo.png',
                'type' => 'text',
                'group' => 'general',
                'label' => '网站Logo',
                'description' => '网站Logo图片路径',
                'is_public' => true,
                'is_required' => false,
                'sort_order' => 4
            ],
            [
                'key' => 'site_favicon',
                'value' => '/favicon.ico',
                'type' => 'text',
                'group' => 'general',
                'label' => '网站图标',
                'description' => '浏览器标签页显示的图标',
                'is_public' => true,
                'is_required' => false,
                'sort_order' => 5
            ],
            [
                'key' => 'admin_email',
                'value' => 'admin@example.com',
                'type' => 'email',
                'group' => 'general',
                'label' => '管理员邮箱',
                'description' => '系统管理员联系邮箱',
                'is_public' => false,
                'is_required' => true,
                'sort_order' => 6
            ],
            [
                'key' => 'timezone',
                'value' => 'Asia/Shanghai',
                'type' => 'select',
                'group' => 'general',
                'label' => '时区设置',
                'description' => '系统默认时区',
                'options' => json_encode([
                    'Asia/Shanghai' => '中国标准时间 (UTC+8)',
                    'UTC' => '协调世界时 (UTC+0)',
                    'America/New_York' => '美国东部时间 (UTC-5)',
                    'Europe/London' => '英国时间 (UTC+0)',
                    'Asia/Tokyo' => '日本标准时间 (UTC+9)'
                ]),
                'is_public' => true,
                'is_required' => true,
                'sort_order' => 7
            ],
            
            // 邮件配置设置
            [
                'key' => 'mail_driver',
                'value' => 'smtp',
                'type' => 'select',
                'group' => 'email',
                'label' => '邮件驱动',
                'description' => '邮件发送驱动类型',
                'options' => json_encode([
                    'smtp' => 'SMTP',
                    'sendmail' => 'Sendmail',
                    'mailgun' => 'Mailgun',
                    'ses' => 'Amazon SES',
                    'log' => '日志模式（测试用）'
                ]),
                'is_public' => false,
                'is_required' => true,
                'sort_order' => 1
            ],
            [
                'key' => 'mail_host',
                'value' => 'smtp.gmail.com',
                'type' => 'text',
                'group' => 'email',
                'label' => 'SMTP主机',
                'description' => 'SMTP服务器地址',
                'is_public' => false,
                'is_required' => false,
                'sort_order' => 2
            ],
            [
                'key' => 'mail_port',
                'value' => '587',
                'type' => 'number',
                'group' => 'email',
                'label' => 'SMTP端口',
                'description' => 'SMTP服务器端口号',
                'is_public' => false,
                'is_required' => false,
                'sort_order' => 3
            ],
            [
                'key' => 'mail_username',
                'value' => '',
                'type' => 'text',
                'group' => 'email',
                'label' => 'SMTP用户名',
                'description' => 'SMTP认证用户名',
                'is_public' => false,
                'is_required' => false,
                'sort_order' => 4
            ],
            [
                'key' => 'mail_password',
                'value' => '',
                'type' => 'password',
                'group' => 'email',
                'label' => 'SMTP密码',
                'description' => 'SMTP认证密码',
                'is_public' => false,
                'is_required' => false,
                'sort_order' => 5
            ],
            [
                'key' => 'mail_encryption',
                'value' => 'tls',
                'type' => 'select',
                'group' => 'email',
                'label' => '加密方式',
                'description' => 'SMTP连接加密方式',
                'options' => json_encode([
                    'tls' => 'TLS',
                    'ssl' => 'SSL',
                    'none' => '无加密'
                ]),
                'is_public' => false,
                'is_required' => false,
                'sort_order' => 6
            ],
            [
                'key' => 'mail_from_address',
                'value' => 'noreply@example.com',
                'type' => 'email',
                'group' => 'email',
                'label' => '发件人邮箱',
                'description' => '系统邮件发送地址',
                'is_public' => false,
                'is_required' => false,
                'sort_order' => 7
            ],
            [
                'key' => 'mail_from_name',
                'value' => 'Laravel Open Admin',
                'type' => 'text',
                'group' => 'email',
                'label' => '发件人名称',
                'description' => '系统邮件发送者名称',
                'is_public' => false,
                'is_required' => false,
                'sort_order' => 8
            ],
            
            // 安全设置
            [
                'key' => 'password_min_length',
                'value' => '8',
                'type' => 'number',
                'group' => 'security',
                'label' => '密码最小长度',
                'description' => '用户密码最少字符数',
                'is_public' => true,
                'is_required' => true,
                'sort_order' => 1
            ],
            [
                'key' => 'password_require_uppercase',
                'value' => 'true',
                'type' => 'boolean',
                'group' => 'security',
                'label' => '密码需要大写字母',
                'description' => '密码是否必须包含大写字母',
                'is_public' => true,
                'is_required' => false,
                'sort_order' => 2
            ],
            [
                'key' => 'password_require_lowercase',
                'value' => 'true',
                'type' => 'boolean',
                'group' => 'security',
                'label' => '密码需要小写字母',
                'description' => '密码是否必须包含小写字母',
                'is_public' => true,
                'is_required' => false,
                'sort_order' => 3
            ],
            [
                'key' => 'password_require_numbers',
                'value' => 'true',
                'type' => 'boolean',
                'group' => 'security',
                'label' => '密码需要数字',
                'description' => '密码是否必须包含数字',
                'is_public' => true,
                'is_required' => false,
                'sort_order' => 4
            ],
            [
                'key' => 'password_require_symbols',
                'value' => 'false',
                'type' => 'boolean',
                'group' => 'security',
                'label' => '密码需要特殊字符',
                'description' => '密码是否必须包含特殊字符',
                'is_public' => true,
                'is_required' => false,
                'sort_order' => 5
            ],
            [
                'key' => 'login_max_attempts',
                'value' => '5',
                'type' => 'number',
                'group' => 'security',
                'label' => '登录最大尝试次数',
                'description' => '用户登录失败最大尝试次数',
                'is_public' => false,
                'is_required' => true,
                'sort_order' => 6
            ],
            [
                'key' => 'login_lockout_duration',
                'value' => '15',
                'type' => 'number',
                'group' => 'security',
                'label' => '登录锁定时长（分钟）',
                'description' => '登录失败后锁定账户的时长',
                'is_public' => false,
                'is_required' => true,
                'sort_order' => 7
            ],
            [
                'key' => 'session_lifetime',
                'value' => '120',
                'type' => 'number',
                'group' => 'security',
                'label' => '会话超时时间（分钟）',
                'description' => '用户会话的有效时长',
                'is_public' => false,
                'is_required' => true,
                'sort_order' => 8
            ],
            [
                'key' => 'enable_two_factor',
                'value' => 'false',
                'type' => 'boolean',
                'group' => 'security',
                'label' => '启用双因素认证',
                'description' => '是否启用双因素认证功能',
                'is_public' => false,
                'is_required' => false,
                'sort_order' => 9
            ],
            
            // 界面设置
            [
                'key' => 'theme',
                'value' => 'light',
                'type' => 'select',
                'group' => 'interface',
                'label' => '系统主题',
                'description' => '系统界面主题风格',
                'options' => json_encode([
                    'light' => '浅色主题',
                    'dark' => '深色主题',
                    'auto' => '跟随系统'
                ]),
                'is_public' => true,
                'is_required' => true,
                'sort_order' => 1
            ],
            [
                'key' => 'language',
                'value' => 'zh-CN',
                'type' => 'select',
                'group' => 'interface',
                'label' => '系统语言',
                'description' => '系统界面显示语言',
                'options' => json_encode([
                    'zh-CN' => '简体中文',
                    'en' => 'English',
                    'ja' => '日本語',
                    'ko' => '한국어'
                ]),
                'is_public' => true,
                'is_required' => true,
                'sort_order' => 2
            ],
            [
                'key' => 'items_per_page',
                'value' => '15',
                'type' => 'select',
                'group' => 'interface',
                'label' => '每页显示条数',
                'description' => '列表页面每页显示的记录数',
                'options' => json_encode([
                    '10' => '10条',
                    '15' => '15条',
                    '20' => '20条',
                    '25' => '25条',
                    '50' => '50条'
                ]),
                'is_public' => true,
                'is_required' => true,
                'sort_order' => 3
            ],
            [
                'key' => 'date_format',
                'value' => 'Y-m-d',
                'type' => 'select',
                'group' => 'interface',
                'label' => '日期格式',
                'description' => '系统日期显示格式',
                'options' => json_encode([
                    'Y-m-d' => '2024-01-01',
                    'Y/m/d' => '2024/01/01',
                    'd/m/Y' => '01/01/2024',
                    'd-m-Y' => '01-01-2024'
                ]),
                'is_public' => true,
                'is_required' => true,
                'sort_order' => 4
            ],
            [
                'key' => 'time_format',
                'value' => 'H:i:s',
                'type' => 'select',
                'group' => 'interface',
                'label' => '时间格式',
                'description' => '系统时间显示格式',
                'options' => json_encode([
                    'H:i:s' => '24小时制 (14:30:00)',
                    'H:i' => '24小时制 (14:30)',
                    'h:i:s A' => '12小时制 (02:30:00 PM)',
                    'h:i A' => '12小时制 (02:30 PM)'
                ]),
                'is_public' => true,
                'is_required' => true,
                'sort_order' => 5
            ],
            [
                'key' => 'sidebar_collapsed',
                'value' => 'false',
                'type' => 'boolean',
                'group' => 'interface',
                'label' => '默认折叠侧边栏',
                'description' => '页面加载时是否默认折叠侧边栏',
                'is_public' => true,
                'is_required' => false,
                'sort_order' => 6
            ],
            
            // 文件上传设置
            [
                'key' => 'upload_max_size',
                'value' => '10240',
                'type' => 'number',
                'group' => 'upload',
                'label' => '最大上传大小（KB）',
                'description' => '单个文件最大上传大小限制',
                'is_public' => true,
                'is_required' => true,
                'sort_order' => 1
            ],
            [
                'key' => 'upload_allowed_types',
                'value' => 'jpg,jpeg,png,gif,pdf,doc,docx,xls,xlsx,zip',
                'type' => 'text',
                'group' => 'upload',
                'label' => '允许上传的文件类型',
                'description' => '允许上传的文件扩展名，用逗号分隔',
                'is_public' => true,
                'is_required' => true,
                'sort_order' => 2
            ],
            [
                'key' => 'upload_path',
                'value' => 'uploads',
                'type' => 'text',
                'group' => 'upload',
                'label' => '上传目录',
                'description' => '文件上传保存的目录路径',
                'is_public' => false,
                'is_required' => true,
                'sort_order' => 3
            ],
            [
                'key' => 'image_max_width',
                'value' => '1920',
                'type' => 'number',
                'group' => 'upload',
                'label' => '图片最大宽度（像素）',
                'description' => '上传图片的最大宽度限制',
                'is_public' => true,
                'is_required' => false,
                'sort_order' => 4
            ],
            [
                'key' => 'image_max_height',
                'value' => '1080',
                'type' => 'number',
                'group' => 'upload',
                'label' => '图片最大高度（像素）',
                'description' => '上传图片的最大高度限制',
                'is_public' => true,
                'is_required' => false,
                'sort_order' => 5
            ],
            [
                'key' => 'enable_image_compression',
                'value' => 'true',
                'type' => 'boolean',
                'group' => 'upload',
                'label' => '启用图片压缩',
                'description' => '是否自动压缩上传的图片',
                'is_public' => false,
                'is_required' => false,
                'sort_order' => 6
            ],
            [
                'key' => 'image_quality',
                'value' => '85',
                'type' => 'number',
                'group' => 'upload',
                'label' => '图片压缩质量',
                'description' => '图片压缩质量（1-100）',
                'is_public' => false,
                'is_required' => false,
                'sort_order' => 7
            ]
        ];

        foreach ($settings as $setting) {
            SystemSetting::updateOrCreate(
                ['key' => $setting['key']],
                $setting
            );
        }
    }
}
